import { createServer } from 'http';

const server = createServer((request, response) => {  
  request.on('error', error => {
    console.error(error);
  });
  
  const buffers: Buffer[] = [];

  request.on('data', chunk => {
    buffers.push(chunk);
  });

  request.on('end', () => {
    const body = Buffer.concat(buffers).toString();

    if (body.length > 0) {
      console.log('Body: ', body);
    } else {
      console.log('Body is empty');
    }

    response.writeHead(200, {
      'Content-Type': 'text/html',
    });

    response.end('Hello World\n');
  });
});

server.listen(8088, () => {
  console.log('Server stared at http://127.0.0.1:8088');
});
